import javax.media.j3d.*;
import java.util.*;

/**
 * The secondary hand behaviour class controls the location of the hand geometry and 
 * allows us to drag objects at around the world.
 */
public class HandBehaviorSecondary extends HandBehaviorGeneric {

    protected boolean[] button = {false, false, false, false, false}; /* Button states */
    
    
    public HandBehaviorSecondary(Hand hand, Sensor trackerSensor, ButtonDevice mouse, TransformGroup viewPlatform, TransformGroup worldBranch){
    	super(hand, trackerSensor, mouse, viewPlatform, worldBranch);
    }

    
	public void processStimulus (Enumeration criteria) {

       	/*Set the states of the buttons*/
        button[0] = buttonDevice.getButton(5);
       	button[1] = buttonDevice.getButton(ButtonDevice.SECONDARY_PICKING_BUTTON);
       	button[2] = buttonDevice.getButton(7);
       	button[3] = buttonDevice.getButton(ButtonDevice.LEVITATE_UP_BUTTON);
       	button[4] = buttonDevice.getButton(ButtonDevice.LEVITATE_DOWN_BUTTON);
       	
       	/* frame movement. Used to keep movement in sync with
       	 * the speed of the computer running it */
       	beginFrameMovement();
       	
       	/* fly up */
		if (button[3])
			levitate(LEVITATE_SPEED);
		/* fly down */
		if (button[4])
			levitate(-LEVITATE_SPEED);
		
		endFrameMovement();
		
		/*Set the look of the hand to represent its actual state*/	
		hand.setTopRightButtonState(button[0]);
		hand.setRightButtonState(button[2]);
		hand.setTopLeftButtonState(button[4]);
		hand.setLeftButtonState(button[3]);
	    hand.setTopMiddleButtonState(button[1]);
	    
	    /*Set the location of the hand*/
	    setHandPosition();	    
       	
        /* Check if we need to drop an object */
        if (!button[1])
        	testForDrop();
        
        /*Check if we are attempting to grab an object */
    	if (button[1])
    		testForGrab();
    
    	wakeupOn(wakeupConditions);
	}
}
